var express = require('express');
var router = express.Router();

// 引入封装的 mysql模块
const mysql = require('../util/mysql/mysql');


//登录
router.post('/', function(req, res, next) {
  mysql.data('select * from users_id where u_name='+req.body.u_username, [], function(err, rows, fields) {
    if (err) return;
    if(rows.length ==0){
      res.send('{"code":"0"}');
    }else if(rows[0].u_password == req.body.u_password&&rows[0].u_type == req.body.u_type){
      var timestamp = Date.parse(new Date());
      var key = timestamp+"#"+rows[0].u_type_id;
      res.send(JSON.stringify({ code: 1,userData:rows[0],key }));
    }else{
      res.send(JSON.stringify({ code: 2}));
    }
  }); 
});


module.exports = router;
